const mysql=require("mysql")

const pool=mysql.createPool({
    host:"",
    user:"",
    password:"",
    database:"testku",
    port:3306,
    connectionLimit:5
})

const exec=function(sql,params=[]){
    return new Promise((resolve,reject)=>{
        pool.getConnection((err,conn)=>{
            if(err){
                console.log("链接数据库出错"+err.message);
                reject(false);
            }else {
                conn.query(sql,params,function(err,results){
                    if(err){
                        console.log("SQL语句执行出错"+err.message);
                        reject(false);
                    }else {
                        resolve(results)
                    }
                })
                conn.release();
            }
        })
    })
}

module.exports={exec}